-- 未来猫冈布奥

function initDoraemon(self, buildingInfo, dbase, pos)
    if type(dbase) ~= "table" or type(dbase["need_property"]) ~= "number" then
        -- 没要求，配置错误
        error("获取不到未来猫冈布奥物品配置！");
        return;
    end

    local petId = dbase["pet_id"];
    -- 建筑图标
    local iconPath = getHeroIconPath(petId);

    -- 领取未来猫任务
    local function takeMission()
        -- 尝试触发
        DungeonActionM.go("take_doraemon_mission", pos);
    end

    -- 完成任务
    local function finishMission()
        if EquipM.isEquiped(dbase["need_property"]) then
            -- 获取type
            local equipType = EquipM.query(dbase["need_property"], "type");
            -- 卸下物品
            if not DungeonActionM.go("do_unequip", 1, equipType) then
                -- 卸下物品
                return;
            end
        end

        if not PetM.getMyPet(petId) then
            -- 尝试触发
            DungeonActionM.go("slime_event", pos, 122);
        else
            DungeonActionM.go("slime_event", pos, 123);
        end

        -- 建筑消失
        playBuildingDisappear(self);
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 格子失效了
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 如果还未领取任务
            local prop = PropM.combine(ME.user, "doraemon", "mission");
            if prop[3] <= 0 then
                self:openBuildingView2(takeMission, nil, buildingInfo["view_text"],
                           getLocStr("leave"), buildingInfo["dialog"], iconPath, true);
            else
                -- 已经领取了任务

                -- 已经修复了动力装置(身上有该装备)
                if ItemM.getAmount(ME.user, dbase["need_property"]) > 0 or EquipM.isEquiped(dbase["need_property"]) then
                    -- 有冈布奥
                    self:openBuildingView2(finishMission, nil, buildingInfo["view_text2"],
                           getLocStr("leave"), buildingInfo["extra_desc"], iconPath, true);
                else
                    -- 还未修复装置
                    self:openBuildingView(nil, 0, buildingInfo["dialog2"], getLocStr("leave"), nil, iconPath, nil, true);
                end
            end

            AudioM.playFx("slime_magician_app");
        end
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
    self.icon:addTouchEventListener(onClicked);
    self.needAnimation =  true;
    self.icon:setPositionY(self.icon:getPositionY() + 15);
end
